// WaitCommand.java
package org.zjx.window.action.impl;


import org.zjx.window.action.Action;
import org.zjx.window.operation.WindowOperation;
import org.zjx.window.window.IWindow;

public class DelayAction extends Action {
    private final long delay;

    public DelayAction(IWindow window, long delay) {
        super(window, false);
        this.delay = delay;
    }

    @Override
    protected void doExecute() throws Exception {
        if (delay <= 0) return;
        long start = System.currentTimeMillis();
        while (System.currentTimeMillis() - start < delay) {
            checkInterruption();
            targetWindow.execute(WindowOperation.delay(Math.min(100, delay - (System.currentTimeMillis() - start))));
        }
    }
}